package de.slothsoft.wasbinich.android.database.local;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

final class SqlDatabaseHelper extends SQLiteOpenHelper {

    static final String DATABASE_NAME = "wasbinich.db"; //$NON-NLS-1$
    static final int DATABASE_VERSION = 3;

    private List<SqlTableHelper> createTableHelpers() {
	List<SqlTableHelper> tableHelpers = new ArrayList<SqlTableHelper>();
	tableHelpers.add(new SqlPictureHelper());
	return tableHelpers;
    }

    private final List<SqlTableHelper> tableHelpers = createTableHelpers();

    public SqlDatabaseHelper(Context context) {
	super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
	for (SqlTableHelper tableHelper : this.tableHelpers) {
	    tableHelper.onCreate(database);
	}
    }

    @Override
    public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
	// to do: add actual update script when necessary
	for (SqlTableHelper tableHelper : this.tableHelpers) {
	    tableHelper.onUpgrade(database, oldVersion, newVersion);
	}
    }
}